import { createWebHistory, createRouter, RouteRecordRaw } from 'vue-router';
/* Layout */
import Layout from '@/layout/index.vue';

// 公共路由
export const constantRoutes: RouteRecordRaw[] = [
    // 主页
    {
        path: '/',
        component: Layout,
        redirect: '/index',
        children: [
            {
                path: '/index',
                name: 'Index',
                component: () => import('@/views/index.vue'),
                meta: {
                    title: '首页',
                },
            },
        ],
    },
    // 登录页
    {
        path: '/login',
        name: 'Login',
        component: () => import('@/views/login.vue'),
    },
    // 注册页
    {
        path: '/register',
        name: 'Register',
        component: () => import('@/views/register.vue'),
    },
    // 找回页
    {
        path: '/retrieve',
        name: 'retrieve',
        component: () => import('@/views/retrieve.vue'),
    },
    // 无权限
    {
        path: '/403',
        name: '403',
        component: () => import('@/views/error/403.vue'),
    },
    // 无页面
    {
        path: '/404',
        name: '404',
        component: () => import('@/views/error/404.vue'),
    },
    {
        path: '/customer',
        component: Layout,
        name: 'customer',
        meta: {
            title: '客户管理',
            icon: '#icon-kehuguanli',
        },
        redirect: '/customer/list',
        children: [
            {
                path: '/customer/list',
                name: 'CustomerList',
                meta: {
                    title: '客户列表',
                    activeMenu: '/customer/list',
                    icon: '#icon-kehuliebiao',
                },
                component: () => import('@/views/customer/list/index.vue'),
            },
        ],
    },
    {
        path: '/product',
        component: Layout,
        meta: {
            title: '产品管理',
            icon: '#icon-chanpinguanli',
        },
        name: 'product',
        redirect: '/product/list',
        children: [
            {
                path: '/product/list',
                name: 'ProductList',
                meta: {
                    title: '产品列表',
                    activeMenu: '/product/list',
                    icon: '#icon-chanpinliebiao',
                },
                component: () => import('@/views/product/list/index.vue'),
            },
            {
                path: '/product/forme',
                name: 'ProductForme',
                meta: {
                    title: '印版资料',
                    activeMenu: '/product/forme',
                    icon: '#icon-yinbanziliao',
                },
                component: () => import('@/views/product/forme/index.vue'),
            },
            {
                path: '/product/analysis',
                name: 'ProductAnalysis',
                meta: {
                    title: '产品分析',
                    activeMenu: '/product/analysis',
                    icon: '#icon-chanpinfenxi',
                },
                component: () => import('@/views/product/analysis/index.vue'),
            },
            {
                path: '/product/log',
                name: 'ProductLog',
                meta: {
                    title: '产品日志',
                    activeMenu: '/product/log',
                    icon: '#icon-chanpinrizhi',
                },
                component: () => import('@/views/product/log/index.vue'),
            },
        ],
    },
    {
        path: '/order',
        component: Layout,
        name: 'order',
        meta: {
            title: '订单管理',
            icon: '#icon-dingdanguanli',
        },
        children: [
            {
                path: '/order/list',
                name: 'OrderList',
                meta: {
                    title: '客户订单',
                    activeMenu: '/order/list',
                    icon: '#icon-kehudingdan',
                },
                component: () => import('@/views/order/list/index.vue'),
            },
            {
                path: '/order/process',
                name: 'OrderProcess',
                meta: {
                    title: '订单处理',
                    activeMenu: '/order/process',
                    icon: '#icon-dingdanchuli',
                },
                component: () => import('@/views/order/process/index.vue'),
            },
            {
                path: '/order/stock',
                name: 'OrderStock',
                meta: {
                    title: '订单库存',
                    activeMenu: '/order/stock',
                    icon: '#icon-dingdankucun',
                },
                component: () => import('@/views/order/stock/index.vue'),
            },
            {
                path: '/order/purchase',
                name: 'OrderPurchase',
                meta: {
                    title: '产品采购',
                    activeMenu: '/order/purchase',
                    icon: '#icon-chanpincaigou',
                },
                component: () => import('@/views/order/purchase/index.vue'),
            },
        ],
    },
    {
        path: '/supplier',
        component: Layout,
        name: 'supplier',
        meta: {
            title: '供应商管理',
            icon: '#icon-gongyingshangguanli',
        },
        children: [
            {
                path: '/supplier/list',
                name: 'SupplierList',
                meta: {
                    title: '供应商列表',
                    activeMenu: '/supplier/list',
                    icon: '#icon-gongyingshangliebiao',
                },
                component: () => import('@/views/supplier/list/index.vue'),
            },
            {
                path: '/supplier/purchase',
                name: 'SupplierPurchase',
                meta: {
                    title: '供应商采购',
                    activeMenu: '/supplier/purchase',
                    icon: '#icon-gongyingshangcaigou',
                },
                component: () => import('@/views/supplier/purchase/index.vue'),
            },
        ],
    },
    {
        path: '/production',
        component: Layout,
        name: 'production',
        meta: {
            title: '生产管理',
            icon: '#icon-shengchanguanli',
        },
        children: [
            {
                path: '/production/list',
                name: 'ProductionList',
                meta: {
                    title: '生产管控',
                    activeMenu: '/production/list',
                    icon: '#icon-shengchanliebiao',
                },
                component: () => import('@/views/production/list/index.vue'),
            },
            {
                path: '/production/outerbox',
                name: 'ProductionOuterbox',
                meta: {
                    title: '外箱生产',
                    activeMenu: '/production/outerbox',
                    icon: '#icon-waixiangshengchan',
                },
                component: () => import('@/views/production/outerbox/index.vue'),
            },
            {
                path: '/production/packouterbox',
                name: 'ProductionPackouterbox',
                meta: {
                    title: '外箱打包',
                    activeMenu: '/production/packouterbox',
                    icon: '#icon-waixiangdabao',
                },
                component: () => import('@/views/production/packouterbox/index.vue'),
            },
            {
                path: '/production/backing',
                name: 'ProductionBacking',
                meta: {
                    title: '裱瓦生产',
                    activeMenu: '/production/backing',
                    icon: '#icon-moqiechufei',
                },
                component: () => import('@/views/production/Backing/index.vue'),
            },
            {
                path: '/production/diecutting',
                name: 'ProductionDiecutting',
                meta: {
                    title: '模切生产',
                    activeMenu: '/production/diecutting',
                    icon: '#icon-moqieshengchan',
                },
                component: () => import('@/views/production/Diecutting/index.vue'),
            },
            {
                path: '/production/innerbox',
                name: 'ProductionInnerbox',
                meta: {
                    title: '内盒生产',
                    activeMenu: '/production/innerbox',
                    icon: '#icon-neiheshengchan',
                },
                component: () => import('@/views/production/Innerbox/index.vue'),
            },
            {
                path: '/production/packinnerbox',
                name: 'ProductionPackinnerbox',
                meta: {
                    title: '内盒打包',
                    activeMenu: '/production/packinnerbox',
                    icon: '#icon-neihedabao',
                },
                component: () => import('@/views/production/Packinnerbox/index.vue'),
            },
        ],
    },
    {
        path: '/warehouse',
        component: Layout,
        name: 'warehouse',
        meta: {
            title: '仓库管理',
            icon: '#icon-cangkuguanli',
        },
        children: [
            {
                path: '/warehouse/list',
                name: 'WarehouseList',
                meta: {
                    title: '仓库列表',
                    activeMenu: '/warehouse/list',
                    icon: '#icon-cangkuliebiao',
                },
                component: () => import('@/views/warehouse/list/index.vue'),
            },
            {
                path: '/warehouse/inventory',
                name: 'WarehouseInventory',
                meta: {
                    title: '仓库库存',
                    activeMenu: '/warehouse/inventory',
                    icon: '#icon-cangkukucun',
                },
                component: () => import('@/views/warehouse/inventory/index.vue'),
            },
            {
                path: '/warehouse/deliver',
                name: 'WarehouseDeliver',
                meta: {
                    title: '订单交付',
                    activeMenu: '/warehouse/deliver',
                    icon: '#icon-dingdanjiaofu',
                },
                component: () => import('@/views/warehouse/deliver/index.vue'),
            },
            {
                path: '/warehouse/outbound',
                name: 'WarehouseOutbound',
                meta: {
                    title: '仓库出库',
                    activeMenu: '/warehouse/outbound',
                    icon: '#icon-cangkuchuku',
                },
                component: () => import('@/views/warehouse/outbound/index.vue'),
            },
            {
                path: '/warehouse/log',
                name: 'WarehouseLog',
                meta: {
                    title: '仓库标签',
                    activeMenu: '/warehouse/log',
                    icon: '#icon-cangkubiaoqian',
                },
                component: () => import('@/views/warehouse/log/index.vue'),
            },
        ],
    },
    {
        path: '/file',
        component: Layout,
        name: 'file',
        meta: {
            title: '文件管理',
            icon: '#icon-wenjianguanli',
        },
        children: [
            {
                path: '/file/list',
                name: 'FileList',
                meta: {
                    title: '文件列表',
                    activeMenu: '/file/list',
                    icon: '#icon-wenjiliebiao',
                },
                component: () => import('@/views/file/list/index.vue'),
            }
        ],
    },
    {
        path: '/system',
        component: Layout,
        name: 'system',
        meta: {
            title: '系统管理',
            icon: '#icon-xitongguanli',
        },
        children: [
            {
                path: '/system/user',
                name: 'SystemUser',
                meta: {
                    title: '系统用户',
                    activeMenu: '/system/user',
                    icon: '#icon-xitongyonghu',
                },
                component: () => import('@/views/system/user/index.vue'),
            },
            {
                path: '/system/role',
                name: 'SystemRole',
                meta: {
                    title: '系统角色',
                    activeMenu: '/system/role',
                    icon: '#icon-xitongjiaose',
                },
                component: () => import('@/views/system/role/index.vue'),
            },
            {
                path: '/system/permission',
                name: 'SystemPermission',
                meta: {
                    title: '系统权限',
                    activeMenu: '/system/permission',
                    icon: '#icon-xitongquanxian',
                },
                component: () => import('@/views/system/permission/index.vue'),
            },
            {
                path: '/system/dictionary',
                name: 'SystemDictionary',
                meta: {
                    title: '字典管理',
                    activeMenu: '/system/dictionary',
                    icon: '#icon-zidianguanli',
                },
                component: () => import('@/views/system/dictionary/index.vue'),
            },
            {
                path: '/system/config',
                name: 'SystemConfig',
                meta: {
                    title: '系统配置',
                    activeMenu: '/system/config',
                    icon: '#icon-xitongpeizhi',
                },
                component: () => import('@/views/system/config/index.vue'),
            },
        ],
    },
    // 系统工具
    {
        path: '/tools',
        component: Layout,
        name: 'tools',
        meta: {
            title: '系统工具',
            icon: '#icon-gongju',
        },
        children: [
            {
                path: '/tools/processData',
                name: 'ToolsProcessData',
                meta: {
                    title: '处理数据',
                    activeMenu: '/tools/processData',
                    icon: '#icon-chulishuju',
                },
                component: () => import('@/views/tools/processData/index.vue'),
            },
        ],
    },
];

// 动态路由
// export const dynamicRoutes: RouteRecordRaw[] = [
//     {
//         path: '/customer',
//         component: Layout,
//         name: 'customer',
//         meta: {
//             title: '客户管理',
//             icon: '#icon-kehuguanli',
//         },
//         redirect: '/customer/list',
//         children: [
//             {
//                 path: '/customer/list',
//                 name: 'CustomerList',
//                 meta: {
//                     title: '客户列表',
//                     activeMenu: '/customer/list',
//                     icon: '#icon-kehuliebiao',
//                 },
//                 component: () => import('@/views/customer/list/index.vue'),
//             },
//         ],
//     },
//     {
//         path: '/product',
//         component: Layout,
//         meta: {
//             title: '产品管理',
//             icon: '#icon-chanpinguanli',
//         },
//         name: 'product',
//         redirect: '/product/list',
//         children: [
//             {
//                 path: '/product/list',
//                 name: 'ProductList',
//                 meta: {
//                     title: '产品列表',
//                     activeMenu: '/product/list',
//                     icon: '#icon-chanpinliebiao',
//                 },
//                 component: () => import('@/views/product/list/index.vue'),
//             },
//             {
//                 path: '/product/log',
//                 name: 'ProductLog',
//                 meta: {
//                     title: '产品日志',
//                     activeMenu: '/product/log',
//                     icon: '#icon-chanpinrizhi',
//                 },
//                 component: () => import('@/views/product/log/index.vue'),
//             },
//         ],
//     },
//     {
//         path: '/order',
//         component: Layout,
//         name: 'order',
//         meta: {
//             title: '订单管理',
//             icon: '#icon-dingdanguanli',
//         },
//         children: [
//             {
//                 path: '/order/list',
//                 name: 'OrderList',
//                 meta: {
//                     title: '客户订单',
//                     activeMenu: '/order/list',
//                     icon: '#icon-kehudingdan',
//                 },
//                 component: () => import('@/views/order/list/index.vue'),
//             },
//             {
//                 path: '/order/process',
//                 name: 'OrderProcess',
//                 meta: {
//                     title: '订单处理',
//                     activeMenu: '/order/process',
//                     icon: '#icon-dingdanchuli',
//                 },
//                 component: () => import('@/views/order/process/index.vue'),
//             },
//         ],
//     },
//     {
//         path: '/supplier',
//         component: Layout,
//         name: 'supplier',
//         meta: {
//             title: '供应商管理',
//             icon: '#icon-gongyingshangguanli',
//         },
//         children: [
//             {
//                 path: '/supplier/list',
//                 name: 'SupplierList',
//                 meta: {
//                     title: '供应商列表',
//                     activeMenu: '/supplier/list',
//                     icon: '#icon-gongyingshangliebiao',
//                 },
//                 component: () => import('@/views/supplier/list/index.vue'),
//             },
//             {
//                 path: '/supplier/purchase',
//                 name: 'SupplierPurchase',
//                 meta: {
//                     title: '供应商采购',
//                     activeMenu: '/supplier/purchase',
//                     icon: '#icon-gongyingshangcaigou',
//                 },
//                 component: () => import('@/views/supplier/purchase/index.vue'),
//             },
//         ],
//     },
//     {
//         path: '/production',
//         component: Layout,
//         name: 'production',
//         meta: {
//             title: '生产管理',
//             icon: '#icon-shengchanguanli',
//         },
//         children: [
//             {
//                 path: '/production/list',
//                 name: 'ProductionList',
//                 meta: {
//                     title: '生产管控',
//                     activeMenu: '/production/list',
//                     icon: '#icon-shengchanliebiao',
//                 },
//                 component: () => import('@/views/production/list/index.vue'),
//             },
//             {
//                 path: '/production/outerbox',
//                 name: 'ProductionOuterbox',
//                 meta: {
//                     title: '外箱生产',
//                     activeMenu: '/production/outerbox',
//                     icon: '#icon-waixiangshengchan',
//                 },
//                 component: () => import('@/views/production/outerbox/index.vue'),
//             },
//             {
//                 path: '/production/packouterbox',
//                 name: 'ProductionPackouterbox',
//                 meta: {
//                     title: '外箱打包',
//                     activeMenu: '/production/packouterbox',
//                     icon: '#icon-waixiangdabao',
//                 },
//                 component: () => import('@/views/production/packouterbox/index.vue'),
//             },
//             {
//                 path: '/production/backing',
//                 name: 'ProductionBacking',
//                 meta: {
//                     title: '裱瓦生产',
//                     activeMenu: '/production/backing',
//                     icon: '#icon-moqiechufei',
//                 },
//                 component: () => import('@/views/production/Backing/index.vue'),
//             },
//             {
//                 path: '/production/diecutting',
//                 name: 'ProductionDiecutting',
//                 meta: {
//                     title: '模切生产',
//                     activeMenu: '/production/diecutting',
//                     icon: '#icon-moqieshengchan',
//                 },
//                 component: () => import('@/views/production/Diecutting/index.vue'),
//             },
//             {
//                 path: '/production/innerbox',
//                 name: 'ProductionInnerbox',
//                 meta: {
//                     title: '内盒生产',
//                     activeMenu: '/production/innerbox',
//                     icon: '#icon-neiheshengchan',
//                 },
//                 component: () => import('@/views/production/Innerbox/index.vue'),
//             },
//             {
//                 path: '/production/packinnerbox',
//                 name: 'ProductionPackinnerbox',
//                 meta: {
//                     title: '内盒打包',
//                     activeMenu: '/production/packinnerbox',
//                     icon: '#icon-neihedabao',
//                 },
//                 component: () => import('@/views/production/Packinnerbox/index.vue'),
//             },
//         ],
//     },
//     {
//         path: '/warehouse',
//         component: Layout,
//         name: 'warehouse',
//         meta: {
//             title: '仓库管理',
//             icon: '#icon-cangkuguanli',
//         },
//         children: [
//             {
//                 path: '/warehouse/list',
//                 name: 'WarehouseList',
//                 meta: {
//                     title: '仓库列表',
//                     activeMenu: '/warehouse/list',
//                     icon: '#icon-cangkuliebiao',
//                 },
//                 component: () => import('@/views/warehouse/list/index.vue'),
//             },
//             {
//                 path: '/warehouse/inventory',
//                 name: 'WarehouseInventory',
//                 meta: {
//                     title: '仓库库存',
//                     activeMenu: '/warehouse/inventory',
//                     icon: '#icon-cangkukucun',
//                 },
//                 component: () => import('@/views/warehouse/inventory/index.vue'),
//             },
//             {
//                 path: '/warehouse/deliver',
//                 name: 'WarehouseDeliver',
//                 meta: {
//                     title: '订单交付',
//                     activeMenu: '/warehouse/deliver',
//                     icon: '#icon-dingdanjiaofu',
//                 },
//                 component: () => import('@/views/warehouse/deliver/index.vue'),
//             },
//             {
//                 path: '/warehouse/outbound',
//                 name: 'WarehouseOutbound',
//                 meta: {
//                     title: '仓库出库',
//                     activeMenu: '/warehouse/outbound',
//                     icon: '#icon-cangkuchuku',
//                 },
//                 component: () => import('@/views/warehouse/outbound/index.vue'),
//             },
//             {
//                 path: '/warehouse/label',
//                 name: 'WarehouseLabel',
//                 meta: {
//                     title: '仓库标签',
//                     activeMenu: '/warehouse/label',
//                     icon: '#icon-cangkubiaoqian',
//                 },
//                 component: () => import('@/views/warehouse/label/index.vue'),
//             },
//         ],
//     },
//     {
//         path: '/system',
//         component: Layout,
//         name: 'system',
//         meta: {
//             title: '系统管理',
//             icon: '#icon-xitongguanli',
//         },
//         children: [
//             {
//                 path: '/system/user',
//                 name: 'SystemUser',
//                 meta: {
//                     title: '系统用户',
//                     activeMenu: '/system/user',
//                     icon: '#icon-xitongyonghu',
//                 },
//                 component: () => import('@/views/system/user/index.vue'),
//             },
//             {
//                 path: '/system/role',
//                 name: 'SystemRole',
//                 meta: {
//                     title: '系统角色',
//                     activeMenu: '/system/role',
//                     icon: '#icon-xitongjiaose',
//                 },
//                 component: () => import('@/views/system/role/index.vue'),
//             },
//             {
//                 path: '/system/permission',
//                 name: 'SystemPermission',
//                 meta: {
//                     title: '系统权限',
//                     activeMenu: '/system/permission',
//                     icon: '#icon-xitongquanxian',
//                 },
//                 component: () => import('@/views/system/permission/index.vue'),
//             },
//             {
//                 path: '/system/dictionary',
//                 name: 'SystemDictionary',
//                 meta: {
//                     title: '字典管理',
//                     activeMenu: '/system/dictionary',
//                     icon: '#icon-zidianguanli',
//                 },
//                 component: () => import('@/views/system/dictionary/index.vue'),
//             },
//             {
//                 path: '/system/config',
//                 name: 'SystemConfig',
//                 meta: {
//                     title: '系统配置',
//                     activeMenu: '/system/config',
//                     icon: '#icon-xitongpeizhi',
//                 },
//                 component: () => import('@/views/system/config/index.vue'),
//             },
//         ],
//     },
// ];

const router = createRouter({
    // history模式
    history: createWebHistory(),
    // 公共路由
    routes: constantRoutes,
    // 保存的滚动位置，仅在使用浏览器的前进/后退按钮时生效。如果通过编程方式跳转，该参数为 null。
    scrollBehavior(_to, _from, savedPosition) {
        if (savedPosition) {
            return savedPosition;
        }
        return { top: 0 };
    },
});

export default router;
